package com.cloudbroker.openapi.manage.controller;

import com.cloudbroker.bcs.common.entity.HSBCPSBackVO;
import com.cloudbroker.bcs.common.util.VOUtil;
import com.cloudbroker.bcs.csvc.lightinvesting.api.t2service.LedThreeT2Service;
import com.cloudbroker.bcs.csvc.lightinvesting.api.vo.request.baseRelevanted.CombineApplyQryForm;
import com.cloudbroker.bcs.csvc.lightinvesting.api.vo.response.CombRankQryBackVo;
import com.cloudbroker.bcs.csvc.lightinvesting.api.vo.response.InterestRankQryBackVo;
import com.cloudbroker.bcs.csvc.lightinvesting.api.vo.response.baseRelevanted.CombineApplyQryBackVo;
import com.cloudbroker.bcs.platform.ltb.bizapi.constants.HSBCPSErrorCodes;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.admin.back.*;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.admin.vo.*;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.base.vo.UserVO;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.back.FeedbackAdminList;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.back.FeedbackSubBack;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.vo.PublicManageFeedbackQryForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.feedback.vo.PublicManageFeedbackReplyForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.push.vo.BatchPushForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.viewpoint.result.ViewpointAdminList;
import com.cloudbroker.bcs.platform.ltb.bizapi.service.viewpoint.vo.ViewpointPublicManageQryForm;
import com.cloudbroker.bcs.platform.ltb.bizapi.t2service.admin.*;
import com.cloudbroker.bcs.platform.ltb.common.ext.annotation.SaveLog;
import com.cloudbroker.openapi.manage.util.ExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.cloudbroker.bcs.platform.ltb.common.util.RequestUtil.getSingleParameterMapForBody;

/**
 * Created by world on 16/11/28.
 */
@Controller
public class PublicManageController  {

    @Resource
    private AdminFeedbackT2BizService adminFeedbackT2BizService;

    @Resource
    private AdminT2ViewpointService adminViewpointService;

    @Resource
    private PublicManageT2BizService publicManageT2BizService;

    @Resource
    private AdminBannerT2BizService adminBannerT2BizService;
    @Resource
    private AdminPushT2BizService adminPushT2BizService;

    @Resource
    protected LedThreeT2Service ledThreeT2Service;

    @ResponseBody
    @RequestMapping("/manage/public_manage_feedback_reply")
    @SaveLog(remark = "统一管理平台意见反馈回复")
    public FeedbackSubBack publicManageFeedbackReply(HttpServletRequest request, String jsonpcallback){
        PublicManageFeedbackReplyForm form = getSingleParameterMapForBody(request,PublicManageFeedbackReplyForm.class);
        return VOUtil.setJsonpResult(adminFeedbackT2BizService.public_manage_feedback_reply(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/public_manage_feedback_query")
    @SaveLog(remark = "统一管理平台意见反馈查询")
    public FeedbackAdminList publicManageFeedbackQuery(HttpServletRequest request, String jsonpcallback){
        PublicManageFeedbackQryForm form = getSingleParameterMapForBody(request,PublicManageFeedbackQryForm.class);
        return VOUtil.setJsonpResult(adminFeedbackT2BizService.public_manage_feedback_admin_query(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/public_manage_adviser_viewpoint")
    @SaveLog(remark = "统一管理平台投顾观点查询")
    public ViewpointAdminList viewpointPublicManageList(HttpServletRequest request, String jsonpcallback){
        ViewpointPublicManageQryForm form = getSingleParameterMapForBody(request,ViewpointPublicManageQryForm.class);
        return VOUtil.setJsonpResult(adminViewpointService.viewpointPublicManageList(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/public_manage_user_collect_qry")
    @SaveLog(remark = "用户关注组合查询")
    public UserCollectHistoryList userCollectHistoryListQry(HttpServletRequest request, String jsonpcallback){
        PublicManageUserCollectQryForm form = getSingleParameterMapForBody(request, PublicManageUserCollectQryForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.userCollectHistoryListQry(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/public_manage_user_subscribe_combine_qry")
    @SaveLog(remark = "用户关注组合查询")
    public PMUserSubscribeCombineList userSubscibeCombineListQry(HttpServletRequest request, String jsonpcallback){
        PMUserSubscribeCombineQryForm form = getSingleParameterMapForBody(request, PMUserSubscribeCombineQryForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.userSubscibeCombineListQry(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/public_manage_user_sign_qry")
    @SaveLog(remark = "用户签约投顾查询")
    public UserSignHistoryList userSignHistoryListQry(HttpServletRequest request, String jsonpcallback){
        PublicManageUserSignQryForm form = getSingleParameterMapForBody(request,PublicManageUserSignQryForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.userSignHistoryListQry(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/combine_recommend")
    @SaveLog(remark = "组合推荐")
    public HSBCPSBackVO combineRecommend(HttpServletRequest request, String jsonpcallback){
        PublicManageCombineRecommendForm form = getSingleParameterMapForBody(request,PublicManageCombineRecommendForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageCombineRecommend(form),jsonpcallback);
    }
    /**
     * 新增banner
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/banner_add")
    @SaveLog(remark = "新增banner")
    public HSBCPSBackVO func_banner_add(HttpServletRequest request, String jsonpcallback){
        BannerAddForm form = getSingleParameterMapForBody(request, BannerAddForm.class);
        return VOUtil.setJsonpResult(adminBannerT2BizService.bannerAdd(form), jsonpcallback);
    }
    /**
     * 删除banner
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/banner_delete")
    @SaveLog(remark = "删除banner")
    public HSBCPSBackVO func_banner_delete(HttpServletRequest request, String jsonpcallback){
        BannerDeleteForm form = getSingleParameterMapForBody(request, BannerDeleteForm.class);
        return VOUtil.setJsonpResult(adminBannerT2BizService.bannerDelete(form), jsonpcallback);
    }
    /**
     * 修改banner
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/banner_update")
    @SaveLog(remark = "修改banner")
    public HSBCPSBackVO func_banner_update(HttpServletRequest request, String jsonpcallback){
        BannerUpdateForm form = getSingleParameterMapForBody(request, BannerUpdateForm.class);
        return VOUtil.setJsonpResult(adminBannerT2BizService.bannerUpdate(form), jsonpcallback);
    }
    /**
     * 查询banner
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/banner_qry")
    @SaveLog(remark = "查询banner")
    public AdminBannerListResult func_banner_qry(HttpServletRequest request, String jsonpcallback){
        BannerQryForm form = getSingleParameterMapForBody(request, BannerQryForm.class);
        return VOUtil.setJsonpResult(adminBannerT2BizService.bannerQry(form), jsonpcallback);
    }

    /**
     * 推送消息
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/send_push")
    @SaveLog(remark = "推送消息")
    public PushBackVo func_send_push(HttpServletRequest request,
                                     @RequestParam(value = "push_file", required = false) CommonsMultipartFile push_file, String jsonpcallback){
        AdminNotifyForm form = getSingleParameterMapForBody(request, AdminNotifyForm.class);
        if(push_file!=null && !push_file.isEmpty()) {
            List<BatchPushForm> list = ExcelUtil.parseBatchPushFile(push_file);
            if(list.size()==0){
                return VOUtil.genErrorResult(HSBCPSErrorCodes.PushErrorInfo.PUSH_EXCEL_ERR,PushBackVo.class);
            }
            StringBuilder sb = new StringBuilder();
            for (BatchPushForm batchPushForm : list) {
                sb.append(batchPushForm.getMobile());
                sb.append(",");
            }
            String send_list = sb.toString().substring(0, sb.toString().length() - 1);
            form.setSend_mobile_list(send_list);
        }
            return VOUtil.setJsonpResult(adminPushT2BizService.sendPush(form), jsonpcallback);
    }

    /**
     * 获取消息推送列表
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/push_list")
    @SaveLog(remark = "获取消息推送列表")
    public PushListBackVo func_push_list(HttpServletRequest request, String jsonpcallback){
        PushListForm form = getSingleParameterMapForBody(request, PushListForm.class);
        return VOUtil.setJsonpResult(adminPushT2BizService.getPushList(form), jsonpcallback);
    }


    /**
     * 启用推送任务
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/ennable_push")
    @SaveLog(remark = "启用推送任务")
    public HSBCPSBackVO func_ennable_push(HttpServletRequest request, String jsonpcallback){
        ManageEnableDisableScheduleVo form = getSingleParameterMapForBody(request, ManageEnableDisableScheduleVo.class);
        return VOUtil.setJsonpResult(adminPushT2BizService.func_ennable_push(form), jsonpcallback);
    }

    /**
     * 禁用推送任务
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/disable_push")
    @SaveLog(remark = "禁用推送任务")
    public HSBCPSBackVO func_disable_push(HttpServletRequest request, String jsonpcallback){
        ManageEnableDisableScheduleVo form = getSingleParameterMapForBody(request, ManageEnableDisableScheduleVo.class);
        return VOUtil.setJsonpResult(adminPushT2BizService.func_disable_push(form), jsonpcallback);
    }

    /**
     * 修改定时推送
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/update_push")
    @SaveLog(remark = "修改定时推送")
    public HSBCPSBackVO func_update_push(HttpServletRequest request, String jsonpcallback){
        ManageUpdateScheduleVo form = getSingleParameterMapForBody(request, ManageUpdateScheduleVo.class);
        return VOUtil.setJsonpResult(adminPushT2BizService.func_update_push(form), jsonpcallback);
    }


    @ResponseBody
    @RequestMapping("/manage/adviser_recommend")
    @SaveLog(remark = "投顾推荐")
    public HSBCPSBackVO adviserRecommend(HttpServletRequest request, String jsonpcallback){
        PMAdviserRecommendForm form = getSingleParameterMapForBody(request,PMAdviserRecommendForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageAdviserRecommend(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/viewpoint_recommend")
    @SaveLog(remark = "观点推荐")
    public HSBCPSBackVO viewpointRecommend(HttpServletRequest request, String jsonpcallback){
        PMViewpointRecommendForm form = getSingleParameterMapForBody(request, PMViewpointRecommendForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageViewpointRecommend(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/combine_recommend_qry")
    @SaveLog(remark = "组合推荐列表")
    public PMCombineRecommendList combineRecommendQry(HttpServletRequest request, String jsonpcallback){
        UserVO form =getSingleParameterMapForBody(request, UserVO.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageCombineRecommendQry(form),jsonpcallback);

    }

    @ResponseBody
    @RequestMapping("/manage/adviser_recommend_qry")
    @SaveLog(remark = "投顾推荐列表")
    public PmAdviserRecommendList adviserRecommendQry(HttpServletRequest request, String jsonpcallback){
        UserVO form = getSingleParameterMapForBody(request,UserVO.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageAdviserRecommendQry(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/viewpoint_recommend_qry")
    @SaveLog(remark = "观点推荐列表")
    public PMViewpointRecommendList viewpointRecommendQry(HttpServletRequest request, String jsonpcallback){
        PMViewpointRecommendQryForm form = getSingleParameterMapForBody(request,PMViewpointRecommendQryForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageViewpointRecommendQry(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/adviser_qry")
    @SaveLog(remark = "投顾列表")
    public InterestRankQryBackVo adviserQry(HttpServletRequest request, String jsonpcallback){
        PublicManageAdviserQryForm form = getSingleParameterMapForBody(request,PublicManageAdviserQryForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageAdviserQry(form),jsonpcallback);
    }


    @ResponseBody
    @RequestMapping("/manage/combine_qry")
    @SaveLog(remark = "组合列表")
    public CombRankQryBackVo combineQry(HttpServletRequest request, String jsonpcallback){
        PublicManageCombineQryForm form = getSingleParameterMapForBody(request,PublicManageCombineQryForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageCombineQry(form),jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/viewpoint_qry")
    @SaveLog(remark = "统一管理平台观点查询")
    public PMViewpointList viewpointPublicManageQry(HttpServletRequest request, String jsonpcallback){
        ViewpointPublicManageQryForm form = getSingleParameterMapForBody(request,ViewpointPublicManageQryForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.publicManageViewpointQry(form),jsonpcallback);
    }
    @ResponseBody
    @RequestMapping("/manage/export_push_model")
    @SaveLog(remark = "导出模板")
    public void viewpointPublicManageQry(HttpServletRequest request, HttpServletResponse response, String jsonpcallback){
        ExcelUtil.outputBatchPushFile(response);
    }


//    /**
//     * 组合申请审核通过
//     * @param request
//     * @param jsonpcallback
//     * @return
//     */
//    @ResponseBody
//    @RequestMapping("/manage/combine_apply_verify")
//    @SaveLog(remark = "组合申请审核通过")
//    public CombineApplyVerifyVo func_combine_apply_verify(HttpServletRequest request, String jsonpcallback){
//        CombineApplyVerifyForm form = getSingleParameterMapForBody(request , CombineApplyVerifyForm.class);
////        return VOUtil.setJsonpResult(ledThreeT2Service.func_combine_apply_verify(form), jsonpcallback);
//        return VOUtil.setJsonpResult(publicManageT2BizService.func_combine_apply_verify(form), jsonpcallback);
//    }
//
//    /**
//     * 组合申请审核不通过
//     * @param request
//     * @param jsonpcallback
//     * @return
//     */
//    @ResponseBody
//    @RequestMapping("/manage/combine_apply_notverify")
//    @SaveLog(remark = "组合申请审核不通过")
//    public CombineApplyNotverifyVo func_combine_apply_notverify(HttpServletRequest request, String jsonpcallback){
//        CombineApplyNotverifyForm form = getSingleParameterMapForBody(request , CombineApplyNotverifyForm.class);
////        return VOUtil.setJsonpResult(ledThreeT2Service.func_combine_apply_notverify(form), jsonpcallback);
//        return VOUtil.setJsonpResult(publicManageT2BizService.func_combine_apply_notverify(form), jsonpcallback);
//    }

    /**
     * 投顾组合申请查询
     * @param request
     * @param jsonpcallback
     * @return
     */
    @ResponseBody
    @RequestMapping("/manage/combine_apply_qry")
    @SaveLog(remark = "投顾组合申请查询")
    public CombineApplyQryBackVo func_combine_apply_qry(HttpServletRequest request, String jsonpcallback){
        CombineApplyQryForm form = getSingleParameterMapForBody(request , CombineApplyQryForm.class);
//        return VOUtil.setJsonpResult(ledThreeT2Service.func_combine_apply_qry(form), jsonpcallback);
        return VOUtil.setJsonpResult(publicManageT2BizService.func_combine_apply_qry(form), jsonpcallback);
    }

    @ResponseBody
    @RequestMapping("/manage/leader_register")
    @SaveLog(remark = "投顾注册")
    public LeaderRegisterBack leaderRegister(HttpServletRequest request, String jsonpcallback){
        UserCenterLeaderRegisterForm form = getSingleParameterMapForBody(request , UserCenterLeaderRegisterForm.class);
        return VOUtil.setJsonpResult(publicManageT2BizService.leaderRegister(form), jsonpcallback);
    }



}
